package com.example.harmonyos_ui.slice;

import com.example.harmonyos_ui.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Text;


public class LoginUiButtonSlice extends AbilitySlice {
    private Text push_button_status_text;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_login_ui_button);
        // 获取文本
        push_button_status_text = (Text)findComponentById(ResourceTable.Id_push_button_status_text);
        // 获取两个按钮
        Button login_button = (Button)findComponentById(ResourceTable.Id_login_button);
        Button sing_up_button = (Button)findComponentById(ResourceTable.Id_sign_up_button);
        // 获取布局
        DirectionalLayout login_ui_button_layout = (DirectionalLayout)findComponentById(ResourceTable.Id_login_ui_button_layout);
        // 按钮绑定事件
        login_button.setClickedListener(this::pushLoginButton);
        sing_up_button.setClickedListener(this::pushSignUpButton);
        // 布局绑定事件
        login_ui_button_layout.setClickedListener(this::clickLayout);
    }

    private void pushLoginButton(Component component) {
        push_button_status_text.setText("登录按钮被点击");
    }

    private void pushSignUpButton(Component component) {
        push_button_status_text.setText("注册按钮被点击");
    }

    private void clickLayout(Component component) {
        push_button_status_text.setText("没有按钮被点击");
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
